package com.example.shop_2304.adapter

import android.graphics.Paint
import android.widget.TextView
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.Goods
import com.example.shop_2304.R
import com.example.shop_2304.utils.GlideUtils

class GoodMutilAdapter:BaseMultiItemQuickAdapter<Goods,BaseViewHolder>() {
    init {
        addItemType(0, R.layout.item_goods)
        addItemType(1,R.layout.item_goods)
    }
    override fun convert(holder: BaseViewHolder, item: Goods) {
       //区分多布局，一个是圆形图片一个是圆角图片
        if(holder.itemViewType==0){
            GlideUtils.loadCornerImage(context,item.image,holder.getView(R.id.goods_iv),30)
        }else{
            GlideUtils.loadCircleImage(context,item.image,holder.getView(R.id.goods_iv))
        }

        holder.setText(R.id.goods_name,item.storeName)
        holder.setText(R.id.goods_price,"价格:￥${item.price}")
        holder.setText(R.id.goods_otprice,"原价:￥${item.otPrice}")
        holder.setText(R.id.goods_sale,"已售${item.sales+ item.ficti}件")//销售数量  在后台中销售数量为sales+fici
        //原价会被画横线
        val textView = holder.getView<TextView>(R.id.goods_otprice)
        textView.paintFlags = Paint.STRIKE_THRU_TEXT_FLAG//中划线
    }
}